<?php


namespace app\api\controller;


use app\common\model\AdminAdmin;
use app\common\model\SchoolPettyCash;
use app\common\model\SchoolTeacherLeave;
use app\common\model\StudentActionAbsence;
use app\common\model\StudentActionAcquire;
use app\common\model\StudentActionAttendance;
use app\common\model\StudentActionBehavior;
use app\common\model\StudentActionBurst;
use app\common\model\StudentActionClean;
use app\common\model\StudentActionClothes;
use app\common\model\StudentActionDairy;
use app\common\model\StudentActionDrink;
use app\common\model\StudentActionEat;
use app\common\model\StudentActionEmotion;
use app\common\model\StudentActionHealthy;
use app\common\model\StudentActionMedication;
use app\common\model\StudentActionNurse;
use app\common\model\StudentActionPhoto;
use app\common\model\StudentActionPoop;
use app\common\model\StudentActionRemarks;
use app\common\model\StudentActionShot;
use app\common\model\StudentActionSituation;
use app\common\model\StudentActionSleep;
use app\common\model\StudentActionStudy;
use app\common\model\StudentActionTemperature;
use app\common\model\StudentActionToilet;
use app\common\model\StudentReplaceDiaper;
use app\common\model\StudyClassSign;
use app\common\model\StudyStudentAction;
use app\common\model\StudyStudentBody;
use app\common\model\StudyStudentClass;
use app\common\model\StudyStudentLeave;
use app\common\model\StudyStudentList;
use think\facade\Db;

class Teacher
{
    /**
     * 获取老师信息
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getTeacherInfo()
    {
        $admin_id = input('param.admin_id');
        $users = AdminAdmin::where('id', $admin_id)->find();
        resReturn($users);
    }

    /**
     * 老师首页
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function teacherIndex()
    {
        $admin_id = input('param.admin_id');
        $class_id = Db::table('bl_class_teacher')->where('teacher_id',$admin_id)->column('class_id');
//        $where[] = ['', 'exp', Db::raw("FIND_IN_SET('{$admin_id}', teacher)")];
        $class = StudyStudentClass::whereIn('id',$class_id)
            ->where('status', 1)
            ->select();
        foreach ($class as $k => $v) {
            $child = StudyStudentList::where('class_id', $v['id'])->where('end_time', '>=', time())->select();
            foreach ($child as $key => $value) {
                $child[$key]['is_leave'] = StudyStudentLeave::where('student_id', $v['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find() ? 1 : 0;
            }
            $class[$k]['student_count'] = count($child);
            $class[$k]['student'] = $child;
        }
        resReturn($class);
    }

    /**
     * 班级详情
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getClassInfo()
    {
        $id = input('param.id');
        $class = StudyStudentClass::where('id', $id)
            ->select();
        foreach ($class as $k => $v) {
            $child = StudyStudentList::where('class_id', $v['id'])->where('end_time', '>=', time())->select();
            foreach ($child as $key => $value) {
                $child[$key]['is_leave'] = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find() ? 1 : 0;
            }
            $class[$k]['student_count'] = count($child);
            $class[$k]['student'] = $child;
        }
        resReturn($class);
    }

    /**
     * 班级签到
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function classSign()
    {
        $admin_id = input('param.admin_id');
        $class_id = input('param.class_id');
        $student_count = input('param.student_count');
        $level_count = input('param.level_count');
        $is_sign = StudyClassSign::where('class_id', $class_id)
            ->whereTime('add_time', 'today')
            ->find();
        if ($is_sign) resReturn('', '今日已签到', 101);
        StudyClassSign::create([
            'class_id' => $class_id,
            'add_time' => time(),
            'student_count' => $student_count,
            'level_count' => $level_count,
            'admin_id' => $admin_id,
        ]) ? resReturn('', '签到成功', 200) : resReturn('', '签到失败', 101);
    }

    /**
     * 学生信息
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getStudentInfo()
    {
        $id = input('param.id');
        $data = StudyStudentList::where('id', $id)->find();
        resReturn($data);
    }

    /**
     * 编辑学生信息
     */
    public function editStudentInfo()
    {
        $student_id = input('param.student_id');
        $height = input('param.height');
        $weight = input('param.weight');
        $head_length = input('param.head_length');
        $admin_id = input('param.admin_id');
        StudyStudentList::where('id', $student_id)
            ->update([
                'height' => $height,
                'weight' => $weight,
                'head_length' => $head_length,
            ]);
        StudyStudentBody::create([
            'height' => $height,
            'weight' => $weight,
            'head_length' => $head_length,
            'student_id' => $student_id,
            'admin_id' => $admin_id,
            'add_time' => time(),
        ]) ? resReturn('', '设定成功', 200) : resReturn('', '设定失败', 101);
    }

    /**
     * 活动情况
     */
    public function actionSituation()
    {

        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }
        $situation_name = input('param.situation_name', '');
        $situation_detail = input('param.situation_detail', '');
        $situation_img = input('param.situation_img', '');
        $add_time = input('param.add_time', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        $admin_id = input('param.admin_id', '');
        foreach ($student as $v) {
            $id = StudentActionSituation::insertGetId([
                'situation_name' => $situation_name,
                'student_id' => $v,
                'situation_detail' => $situation_detail,
                'situation_img' => $situation_img,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 1,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);

    }

    /**
     * 更换尿布
     */
    public function replaceDiaper()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $replace_diaper = input('param.replace_diaper');
        $diaper_type = input('param.diaper_type');
        $replace_info = input('param.replace_info');
        $add_time = input('param.add_time');
        $admin_id = input('param.admin_id', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentReplaceDiaper::insertGetId([
                'student_id' => $v,
                'replace_diaper' => $replace_diaper,
                'diaper_type' => $diaper_type,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'replace_info' => $replace_info,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 2,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 喂奶情况
     */
    public function actionNurse()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $add_time = input('param.add_time');
        $admin_id = input('param.admin_id', 0);
        $nurse_type = input('param.nurse_type', '');
        $diaper_num = input('param.diaper_num', 0);
        $action_info = input('param.action_info', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionNurse::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'nurse_type' => $nurse_type,
                'diaper_num' => $diaper_num,
                'action_info' => $action_info,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 3,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 用餐情况
     */
    public function actionEat()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $add_time = input('param.add_time');
        $admin_id = input('param.admin_id', 0);
        $eat_type = input('param.eat_type', '');
        $eat_num = input('param.eat_num', '');
        $eat_food = input('param.eat_food', '');
        $action_info = input('param.action_info', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionEat::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'eat_type' => $eat_type,
                'eat_num' => $eat_num,
                'eat_food' => $eat_food,
                'action_info' => $action_info,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 4,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 用药情况
     */
    public function actionMedication()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $sign_img = input('param.sign_img', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionMedication::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'sign_img' => $sign_img,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 5,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 睡觉情况
     */
    public function actionSleep()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $start_time = input('param.start_time', '');
        $end_time = input('param.end_time', '');
        $sleep_time = input('param.sleep_time', '');
        $sleep_type = input('param.sleep_type', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionSleep::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'start_time' => $start_time,
                'end_time' => $end_time,
                'sleep_time' => $sleep_time,
                'sleep_type' => $sleep_type,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 6,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 清洁情况
     */
    public function actionClean()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $clean_type = input('param.clean_type', '');
        $is_self = input('param.is_self', '');
        $clean_info = input('param.clean_info', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionClean::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'clean_type' => $clean_type,
                'is_self' => $is_self,
                'clean_info' => $clean_info,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 7,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 饮品情况
     */
    public function actionDrink()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $drink_tool = input('param.drink_tool', '');
        $drink_type = input('param.drink_type', '');
        $drink_num = input('param.drink_num', 0);
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionDrink::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'drink_tool' => $drink_tool,
                'drink_type' => $drink_type,
                'drink_num' => $drink_num,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 8,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 便便情况
     */
    public function actionPoop()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $poop_detail = input('param.poop_detail', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionPoop::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'poop_detail' => $poop_detail,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 9,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 情绪情况
     */
    public function actionEmotion()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $emotion_detail = input('param.emotion_detail', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionEmotion::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'emotion_detail' => $emotion_detail,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 10,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 到/离校情况
     */
    public function actionAttendance()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }
        

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $shuttle_type = input('param.shuttle_type', '');
        $shuttle_img = input('param.shuttle_img', '');
        $attendance_type = input('param.attendance_type', '到校');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionAttendance::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'shuttle_type' => $shuttle_type,
                'shuttle_img' => $shuttle_img,
                'attendance_type' => $attendance_type,
                'color' => $color,
                'image' => $image,
            ]);
            if ($attendance_type == '到校') {
                StudyStudentAction::create([
                    'student_id' => $v,
                    'action_type' => 11,
                    'action_id' => $id,
                    'add_time' => time(),
                    'admin_id' => $admin_id,
                ]);
            } else {
                StudyStudentAction::create([
                    'student_id' => $v,
                    'action_type' => 12,
                    'action_id' => $id,
                    'add_time' => time(),
                    'admin_id' => $admin_id,
                ]);
            }
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 13=体温
     */
    public function actionTemperature()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $temperature = input('param.temperature', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionTemperature::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'temperature' => $temperature,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 13,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 14=突发事件
     */
    public function actionBurst()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $burst_info = input('param.burst_info', '');
        $burst_img = input('param.burst_img', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionBurst::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'burst_info' => $burst_info,
                'burst_img' => $burst_img,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 14,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 行为观察
     */
    public function actionBehavior()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $behavior_info = input('param.behavior_info', '');
        $behavior_img = input('param.behavior_img', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionBehavior::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'behavior_info' => $behavior_info,
                'behavior_img' => $behavior_img,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 15,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 16=添置
     */
    public function actionAcquire()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $acquire_info = input('param.acquire_info', '');
        $is_read = input('param.is_read', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionAcquire::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'acquire_info' => $acquire_info,
                'is_read' => $is_read,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 16,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 17=备注
     */
    public function actionRemarks()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionRemarks::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 17,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 18=缺勤
     */
    public function actionAbsence()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $absence_type = input('param.absence_type', '');
        $start_time = input('param.start_time', '');
        $end_time = input('param.end_time', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionAbsence::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'absence_type' => $absence_type,
                'start_time' => $start_time,
                'end_time' => $end_time,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 18,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 19=视频
     */
    public function actionShot()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $shot_info = input('param.shot_info', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionShot::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'shot_info' => $shot_info,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 19,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 20=健康
     */
    public function actionHealthy()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $healthy_type = input('param.healthy_type', '');
        $healthy_info = input('param.healthy_info', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionHealthy::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'healthy_type' => $healthy_type,
                'healthy_info' => $healthy_info,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 20,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 21=发展学习
     */
    public function actionStudy()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $study_img = input('param.study_img', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionStudy::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'study_img' => $study_img,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 21,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * ,22=更换衣物
     */
    public function actionClothes()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $clothes_type = input('param.clothes_type', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionClothes::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'clothes_type' => $clothes_type,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 22,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 23=如厕记录
     */
    public function actionToilet()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $toilet_type = input('param.toilet_type', '');
        $toilet_img = input('param.toilet_img', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionToilet::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'toilet_type' => $toilet_type,
                'toilet_img' => $toilet_img,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 23,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 24=今日日记
     */
    public function actionDairy()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $dairy_img = input('param.dairy_img', null);
        $is_read = input('param.is_read', 0);
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionDairy::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'dairy_img' => $dairy_img,
                'is_read' => $is_read,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 24,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }
    /**
     * 25=照片
     */
    public function actionPhoto()
    {
        $add_type = input('param.add_type', 1);
        if ($add_type == 1) {
            $student_id = input('param.student_id');
            $student[] = $student_id;
        } else {
            $class_id = input('param.class_id');
            $child = StudyStudentList::where('class_id', $class_id)->where('end_time', '>=', time())->select();
            $student = [];
            foreach ($child as $key => $value) {
                $is_leave = StudyStudentLeave::where('student_id', $value['id'])
                    ->where('start_time', '<', time())
                    ->where('end_time', '>', time())
                    ->find();
                if (!$is_leave) {
                    $student[] = $value['id'];
                }
            }
        }

        $admin_id = input('param.admin_id', 0);
        $add_time = input('param.add_time', '');
        $action_info = input('param.action_info', '');
        $shot_info = input('param.shot_info', '');
        $image = input('param.image', '');
        $color = input('param.color', '');
        foreach ($student as $v) {
            $id = StudentActionPhoto::insertGetId([
                'student_id' => $v,
                'add_time' => strtotime($add_time),
                'admin_id' => $admin_id,
                'action_info' => $action_info,
                'shot_info' => $shot_info,
                'color' => $color,
                'image' => $image,
            ]);
            StudyStudentAction::create([
                'student_id' => $v,
                'action_type' => 25,
                'action_id' => $id,
                'add_time' => time(),
                'admin_id' => $admin_id,
            ]);
        }
        resReturn('', '记录成功', 200);
    }

    /**
     * 查看学生情况
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function studentAction()
    {
        $student_id = input('param.student_id');
        $action_type = input('param.action_type', 0);
        $where['student_id'] = $student_id;
        if ($action_type)  $where['action_type'] = $action_type;
        $time = input('param.time', toDate(time(), 'Y-m-d'));
        $action = StudyStudentAction::with([
            'get_teacher' => function ($a) {
                $a->field('id,nickname');
            }
        ])->where($where)
            ->order('id desc')
            ->whereBetween('add_time', [strtotime($time . ' 00:00:00'), strtotime($time . ' 23:59:59')])
            ->select();
        foreach ($action as $key => $value) {
            $action[$key]['add_time'] = toDate($value['add_time'], 'H:i');
            switch ($value['action_type']) {
                case 1:
                    $data = StudentActionSituation::where('id', $value['action_id'])->find();
                    $data['situation_img'] = json_decode($data['situation_img'], true);
                    $action[$key]['action'] = $data;
                    break;
                case 2:
                    $action[$key]['action'] = StudentReplaceDiaper::where('id', $value['action_id'])->find();
                    break;
                case 3:
                    $action[$key]['action'] = StudentActionNurse::where('id', $value['action_id'])->find();
                    break;
                case 4:
                    $action[$key]['action'] = StudentActionEat::where('id', $value['action_id'])->find();
                    break;
                case 5:
                    $action[$key]['action'] = StudentActionMedication::where('id', $value['action_id'])->find();
                    break;
                case 6:
                    $action[$key]['action'] = StudentActionSleep::where('id', $value['action_id'])->find();
                    break;
                case 7:
                    $data = StudentActionClean::where('id', $value['action_id'])->find();
                    $data['clean_info'] = implode(json_decode($data['clean_info'], true));
                    $action[$key]['action'] = $data;
                    break;
                case 8:
                    $action[$key]['action'] = StudentActionDrink::where('id', $value['action_id'])->find();
                    break;
                case 9:
                    $data = StudentActionPoop::where('id', $value['action_id'])->find();
                    $data['poop_detail'] = implode(json_decode($data['poop_detail'], true));
                    $action[$key]['action'] = $data;
                    break;
                case 10:
                    $action[$key]['action'] = StudentActionEmotion::where('id', $value['action_id'])->find();
                    break;
                case 11:
                case 12:
                    $action[$key]['action'] = StudentActionAttendance::where('id', $value['action_id'])->find();
                    break;
                case 13:
                    $action[$key]['action'] = StudentActionTemperature::where('id', $value['action_id'])->find();
                    break;
                case 14:
                    $data = StudentActionBurst::where('id', $value['action_id'])->find();
                    $data['burst_img'] = json_decode($data['burst_img'], true);
                    $action[$key]['action'] = $data;
                    break;
                case 15:
                    $data = StudentActionBehavior::where('id', $value['action_id'])->find();
                    $data['behavior_img'] = json_decode($data['behavior_img'], true);
                    $action[$key]['action'] = $data;
                    break;
                case 16:
                    $action[$key]['action'] = StudentActionAcquire::where('id', $value['action_id'])->find();
                    break;
                case 17:
                    $action[$key]['action'] = StudentActionRemarks::where('id', $value['action_id'])->find();
                    break;
                case 18:
                    $action[$key]['action'] = StudentActionAbsence::where('id', $value['action_id'])->find();
                    break;
                case 19:
                    $data = StudentActionShot::where('id', $value['action_id'])->find();
                    $data['shot_info'] = json_decode($data['shot_info'], true);
                    $action[$key]['action'] = $data;
                    break;
                case 25:
                    $data = StudentActionPhoto::where('id', $value['action_id'])->find();
                    $data['shot_info'] = json_decode($data['shot_info'], true);
                    $action[$key]['action'] = $data;
                    break;
                case 20:
                    $data = StudentActionHealthy::where('id', $value['action_id'])->find();
                    $data['healthy_info'] = json_decode($data['healthy_info'], true);
                    $action[$key]['action'] = $data;
                    break;
                case 21:
                    $data = StudentActionStudy::where('id', $value['action_id'])->find();
                    $data['study_img'] = json_decode($data['study_img'], true);
                    $action[$key]['action'] = $data;
                    break;
                case 22:
                    $action[$key]['action'] = StudentActionClothes::where('id', $value['action_id'])->find();
                    break;
                case 23:
                    $action[$key]['action'] = StudentActionToilet::where('id', $value['action_id'])->find();
                    break;
                case 24:
                    $data = StudentActionDairy::where('id', $value['action_id'])->find();
                    $data['dairy_img'] = json_decode($data['dairy_img'], true);
                    $action[$key]['action'] = $data;
                    break;
                default:
                    $action[$key]['action'] = [];
                    break;
            }
        }
        resReturn($action, '记录成功', 200);
    }

    /**
     * 老师请假
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function teacherLeave()
    {
        $admin_id = input('param.admin_id');
        $username = input('param.username');
        $leave_type = input('param.leave_type');
        $start_time = input('param.start_time');
        $end_time = input('param.end_time');
        $day = input('param.day');
        $leave_info = input('param.leave_info');
        $is_level = SchoolTeacherLeave::where('admin_id', $admin_id)
            ->whereTime('start_time', 'month')
            ->find();
        if ($is_level)  resReturn('', '每月最多请假一次', 101);
        SchoolTeacherLeave::create([
            'admin_id' => $admin_id,
            'username' => $username,
            'leave_type' => $leave_type,
            'start_time' => $start_time,
            'day' => $day,
            'end_time' => $end_time,
            'leave_info' => $leave_info,
        ]) ? resReturn('', '记录成功,请等待审核', 200) : resReturn('', '提交失败', 101);
    }

    //请假类型
    public function leaveType(){
        $data = Db::table('bl_school_teacher_leave_type')->select();
        resReturn($data, '记录成功', 200);
    }
    
    //消费项目
    public function projectList(){
        $data = Db::table('bl_school_consumptio_items')->select();
        resReturn($data, '记录成功', 200);
    }
    /**
     * 请假记录
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function teacherLeaveHistory()
    {
        $admin_id = input('param.admin_id');
        $month = SchoolTeacherLeave::where('admin_id', $admin_id)
            ->whereTime('start_time', 'month')
            ->order('id desc')
            ->select();
        $year = SchoolTeacherLeave::where('admin_id', $admin_id)
            ->whereTime('start_time', 'year')
            ->order('id desc')
            ->select();
        $all = SchoolTeacherLeave::where('admin_id', $admin_id)
            ->order('id desc')
            ->select();
        resReturn([
            'month' => $month,
            'year' => $year,
            'all' => $all
        ], '获取成功', 200);
    }

    /**
     * 备用金申请
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function pettyCash()
    {
        $admin_id = input('param.admin_id');
        $cash_info = input('param.cash_info');
        $cash_price = input('param.cash_price');
        $cash_note = input('param.cash_note');
        $cash_image = input('param.cash_image');
        $department = input('param.department');
        $admin = AdminAdmin::where('id', $admin_id)->find();
        $data = [
            'cash_info' => $cash_info,
            'cash_price' => $cash_price,
            'cash_note' => $cash_note,
            'admin_id' => $admin_id,
            'cash_image' => $cash_image,
            'school_id' => $admin['school_id'],
            'create_time' => toDate(time()),
            'department'=>$department,
        ];
        $role_id = Db::table('bl_admin_admin_role')
            ->where('admin_id',$admin_id)
            ->column('role_id');
        //4财务端 5招生主管 6教学主任 7招生人员 9教师
//        if (in_array(7,$role_id)||in_array(9,$role_id)){
//            $data['director_audit'] = 1;
//        }
        if (in_array(5,$role_id)||in_array(6,$role_id)){
            $data['director_audit'] = 2;
        }
        if (in_array(4,$role_id)){
            $data['director_audit'] = 2;
            $data['finance_audit'] = 2;
        }
        SchoolPettyCash::create($data) ? resReturn('', '记录成功,请等待审核', 200) : resReturn('', '提交失败', 101);
    }

    /**
     * 备用金申请记录
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function pettyCashHistory()
    {
        $admin_id = input('param.admin_id');
        $list = SchoolPettyCash::where('admin_id', $admin_id)
            ->order('id desc')
            ->select();
        resReturn($list, '获取成功', 200);
    }

    /**
     * 交接账号
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function handoverAccount()
    {
        $admin_id = input('param.admin_id');
        $old_phone = input('param.old_phone');
        $new_phone = input('param.new_phone');
        $sms_code = input('param.sms_code');
        $new_password = input('param.new_password');
        $admin = AdminAdmin::where('id', $admin_id)->find();
        if ($old_phone != $admin['mobile']) resReturn('', '原手机号输入错误', 101);
        $is_set = dataFind('bl_sms_code', ['mobile'=> $new_phone], '*', 'id DESC');
        if (!$is_set) resReturn([], '请先发送短信!', -101);
        if ($sms_code != $is_set['sms_code']) resReturn([], '短信输入错误!', -101);
        if (($is_set['add_time'] + 600) < time()) resReturn([], '短信已过期,请重新获取!', -101);
        if ($is_set['is_use'] != 0) resReturn([], '短信已失效,请重新获取!', -101);
        dataUpdate('bl_sms_code', ['id' => $is_set['id']], ['is_use' => 1]);
        AdminAdmin::where('id', $admin_id)->update([
            'mobile' => $new_phone,
            'password' => set_password($new_password)
        ]) ? resReturn('', '提交成功', 200) : resReturn('', '提交失败', 101);
    }

    public function editTeacherAvatar()
    {
        $id = input('param.id');
        $avatar = input('param.head_portrait');
        $res = AdminAdmin::where('id',$id)->update(['head_portrait'=>$avatar]);
        $res !== false? resReturn('', '修改成功!', 200) : resReturn('', '修改失败!', 101);
    }

    public function photoCount()
    {
        $admin_id = input('admin_id');
        $list = StudentActionPhoto::where('admin_id',$admin_id)->select();
        $res = [];
        $i = 1;
        foreach ($list as $v){
            foreach (json_decode($v['shot_info'],true) as $val){
                $res[] = [
                    'id'=>$i,
                    'photo'=>$val,
                    'create_time'=>date('Y-m-d H:i:s',$v['add_time'])
                ];
                $i++;
            }
        }
        resReturn($res);
    }



}